package pw.hais.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pw.hais.entity.User;
import pw.hais.service.UserService;

/**
 * 登录控制器
 * 
 * @author Hello_海生
 * @date 2014年7月23日
 */
@WebServlet(name = "User", urlPatterns = { "/user" })
public class UserServlet extends BasesServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);	//调用父类方法
		
		String username=getString("username");
		String password=getString("password");
		
		if("".equals(username) || "".equals(password)){
			val.put(code, "404");
			val.put(msg, "请填写账号密码。");
			val.put(data, "");
		}else{
			User u = new User();
			u.setUsername(username);
			u.setPassword(password);
			
			UserService userService = new UserService();
			val = userService.login(u);
		}
		printJSON(val);	//输出JSON
		
	}

}
